/***************************************************************
 
 DwarfCraft - Dwarf Fortress / Minecraft clone
 Copyright 2011 Jeremy Bridon - See License.txt for info
 
 This source file is developed and maintained by:
 + Jeremy Bridon jbridon@cores2.com
 
 File: WorldGenerator.h/cpp
 Desc: Core world generation algorithm and container. The
 overall approach is a mixture of a Voronoi graph, perlin maps,
 and biome segmentation.
 
 First, a pseud-random distribution of points are made, generating
 a Voronoi graph, which then has each tile defined as either a
 land or water tile based on a perlin depth mask and distance from
 the center. Then graph is then used to generate the height, which
 uses the simple rule of "segments are highest away from the shore".
 
 Secondly, this map is interpolated to create a smooth surface,
 which is then turned into the voxel world (contained in a
 WorldContainer object).
 
 Finally, a moister map is generated by creating a perlin mask
 representing moister. Biome rules are then applied, in which
 biomes are defined by a mix of elevation (low, med, high) and
 moister (high, low). Plants, surface blocks, etc. are defined
 by these biomes.
 
 Note: The idea of using a Voronoi graph came from this article:
 http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/
 
***************************************************************/

// Inclusion guard
#ifndef __WORLDGENERATOR_H__
#define __WORLDGENERATOR_H__

#include "WorldContainer.h"
#include "Stack.h"
#include "Vector3.h"
#include "PerlinNoise.h"
#include "PlasmaNoise.h"

/*** External Includes ***/

// Voronoi gen. tools
#include "Voronoi.h"
#include "VPoint.h"
using namespace vor;

// Testing
#include "EasyBMP/EasyBMP.h"
#include "EasyBmp/EasyBMP_Geometry.h"

// Define biomes
static const int BiomeTypesCount = 6;
enum BiomeTypes                 // Elevation        Moister
{
    BiomeTypes_Snow,            // High             High
    BiomeTypes_Tundra,          // High             Low
    BiomeTypes_Grasslands,      // Med              Low
    BiomeTypes_EvergreenForest, // Med              High
    BiomeTypes_TropicalForest,  // Low              High
    BiomeTypes_Desert,          // Low              Low
};

class WorldGenerator
{
public:
    
    // Standard constructor and destructor; prepares the generation system
    WorldGenerator();
    ~WorldGenerator();
    
    // Generate a world, filling the given (assumed allocated) world container
    void Generate(WorldContainer* WorldData, const char* Seed);
    
protected:
    
    // Fill all white spaces that touch this pixel and all other pixels with the given color
    // Uses flood-fill algorithm
    void FloodFill(BMP& Image, int x, int y, RGBApixel Color);
    
    // True if the given point matches the target color
    bool IsColor(BMP& Image, VPoint* Point, RGBApixel TargetColor);
    
private:
    
    // Random number generator
    UtilRand* Random;
    
    // The main world we are working with in this instance
    // Internal reference
    WorldContainer* WorldData;
};

// End inclusion guard
#endif
